<?php
/**
 * Created by PhpStorm.
 * User: allen.qiang
 * Date: 15-6-11
 * Time: 下午2:05
 */

$_REQUEST['subsite'] = 'backend';

require ('core/shop.php');

if (!isset($_REQUEST['label_code']) || empty($_REQUEST['label_code'])) {
    die('缺少参数');
}

$label_code = trim($_REQUEST['label_code']);

$sql = 'SELECT bill_goods_no,distribution_name FROM bill_goods_product WHERE icePack_label = ?';

$rs = $G_SHOP->DBCA->stmt_query($sql,'i',$label_code);

$str = $site_name = '';

if(count($rs)>0){

    for($i=1;$i<=count($rs);$i++){

        $key = $i-1;

        if($key == 0){
            $site_name = $rs[$key]->distribution_name;
        }

        $str .= '<goods_no_'.$i.'>'.substr($rs[$key]->bill_goods_no,-7,7).'</goods_no_'.$i.'>';

        if($i>=8)
            break;

    }

    $str .= '<goods_no_more>总计:'.count($rs).'</goods_no_more>';

}

//如果大于三个汉字 截取前5个汉字
if(strlen($site_name)>12){
    $site_name = substr($site_name,0,12);
}

$xml = "<report>
<_grparam>
    <ice_label>{$label_code}</ice_label>
    <site_name>{$site_name}</site_name>
    {$str}
</_grparam>
</report>";

echo $xml;